package cn.lili.modules.payment.entity.dto;

import cn.hutool.core.util.ArrayUtil;
import cn.lili.common.security.enums.SceneEnums;
import cn.lili.modules.payment.entity.enums.WalletServiceTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 会员余额变动模型
 *
 * @author Chopper
 * @version v1.0
 * 2021-12-01 09:35
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class UserWalletUpdateDTO {

    @ApiModelProperty(value = "变动金额")
    private Double amount;

    @ApiModelProperty(value = "用户id")
    private String userId;

    @ApiModelProperty(value = "用户昵称")
    private String nickname;

    @ApiModelProperty(value = "日志详情")
    private String detail;

    @ApiModelProperty(value = "订单号")
    private String orderSn;

    @ApiModelProperty(value = "变动业务原因")
    private WalletServiceTypeEnum serviceType;

    @ApiModelProperty(value = "第三方支付发起交易号")
    private String outTradeNo;

    @ApiModelProperty(value = "第三方平台付款流水号")
    private String transactionId;

    @ApiModelProperty(value = "场景")
    private SceneEnums scene = SceneEnums.MEMBER;

    @ApiModelProperty(value = "与当前变动关联的平台钱包id")
    private String platformWalletId;


    public static String generateRechargeDescription(String rechargeSn) {
        return String.format("余额充值，充值单号为：%s", rechargeSn);
    }

    public static String generateTradeDescription(PayParam payParam) {
        return payParam.getIsCombine() ? String.format("合单支付，订单号为：%s",
                ArrayUtil.join((payParam.getPayParamItems().stream().map(PayParamItem::getSn).toArray()), ",")) :
                String.format(
                        "订单%s支付",
                        payParam.getPayParamItems().get(0).getSn());

    }
}
